class Solution {
    public:
        long long maximumTripletValue(vector<int>& nums) {
            int n = nums.size();
            vector<int> left(n), right(n);
            int old = nums[0];
            for (int i = 1; i < n; i++) {
                left[i] = old;
                old = max(old, nums[i]);
            }
            old = nums[n - 1];
            for (int i = n - 2; i >= 0; i--) {
                right[i] = old;
                old = max(old, nums[i]);
            }
            long long ans = 0;
            for (int i = 1; i < n; i++) {
                ans = max(ans,(long long)(left[i] - nums[i]) * right[i]);
            }
            return ans;
        }
    };